﻿using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.Rapor
{ 
    public partial class EtiketRaf : DevExpress.XtraReports.UI.XtraReport
    {
        public EtiketRaf(string range)
        {
            InitializeComponent();
        
            myData1.xShelf.Merge(Session.DataManager.ExecuteDataTable("GetBarcodeRAF", range));

            xrLabel1.BeforePrint += xrLabel1_BeforePrint;
        }

        void xrLabel1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
            gr.PageUnit = GraphicsUnit.Millimeter;
            int factor = 10;

            XRLabel label = (XRLabel)sender;

            float newSize = 40F;
            label.Font = new Font("Century", newSize, FontStyle.Regular);

            float stringWidth = gr.MeasureString(label.Text, label.Font).Width;
            float labelWidth = label.HeightF;


            if (labelWidth < stringWidth * factor)
                newSize = label.Font.Size * label.HeightF / stringWidth / factor;

            label.Font = new Font("Century", newSize, FontStyle.Regular);
            gr.Dispose();
        }
    }
}